//
//  TTDiamondDetailImageInfoViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/10/24.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTDiamondDetailImageInfoViewCell.h"

@interface TTDiamondDetailImageInfoViewCell ()

@property (nonatomic, strong) UILabel *leftTitleLabel;
@property (nonatomic, strong) UIImageView *leftPictureView;
@property (nonatomic, strong) UILabel *leftContentLabel;

@property (nonatomic, strong) UILabel *rightTitleLabel;
@property (nonatomic, strong) UIImageView *rightPictureView;
@property (nonatomic, strong) UILabel *rightContentLabel;

@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation TTDiamondDetailImageInfoViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubviews];
    }
    return self;
}

// 查看图片
- (void)clickImageViewBtn
{
    if ([self.delegate respondsToSelector:@selector(lookImageWithUrlString:)]) {
        [self.delegate lookImageWithUrlString:self.dic[@"imageUrlString"]];
    }
}

// 查看视频
- (void)clickVideoBtn
{
    if ([self.delegate respondsToSelector:@selector(lookVideoWithUrlString:)]) {
        [self.delegate lookVideoWithUrlString:self.dic[@"videoUrlString"]];
    }
}

- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    self.leftTitleLabel.text = [NSString stringWithFormat:@"%@: ", dic[@"leftTitle"]];
    self.leftPictureView.image = [UIImage imageNamed:dic[@"leftContent"]];
    self.rightTitleLabel.text = [NSString stringWithFormat:@"%@: ", dic[@"rightTitle"]];
    self.rightPictureView.image = [UIImage imageNamed:dic[@"rightContent"]];
    
    NSString *imageUrlString = dic[@"imageUrlString"];
    NSString *videoUrlString = dic[@"videoUrlString"];
    self.leftContentLabel.hidden = imageUrlString.length > 1;
    self.leftPictureView.hidden = !self.leftContentLabel.hidden;

    self.rightContentLabel.hidden = videoUrlString.length > 1;
    self.rightPictureView.hidden = !self.rightContentLabel.hidden;
    
    self.leftBtn.hidden = self.leftPictureView.hidden;
    self.rightBtn.hidden = self.rightPictureView.hidden;
    
}

- (void)setupSubviews
{
    _leftTitleLabel = [UILabel labelWithTitle:@" " color:UIColorHex(666666) fontSize:14];
    [self.contentView addSubview:_leftTitleLabel];
    [_leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).mas_equalTo(10);
        make.top.height.equalTo(self.contentView);
    }];
    
    _leftPictureView = [[UIImageView alloc] init];
    _leftPictureView.contentMode = UIViewContentModeCenter;
    [self.contentView addSubview:_leftPictureView];
    [_leftPictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftTitleLabel.mas_right);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(10);
    }];
    
    _leftContentLabel = [UILabel labelWithTitle:@"-" color:UIColorHex(666666) fontSize:14];
    [self.contentView addSubview:_leftContentLabel];
    [_leftContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.leftPictureView);
    }];
    
    _rightTitleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:14];
    [self.contentView addSubview:_rightTitleLabel];
    [_rightTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_centerX);
        make.top.height.equalTo(self.contentView);
    }];
    
    _rightPictureView = [[UIImageView alloc] init];
    _rightPictureView.contentMode = UIViewContentModeCenter;
    [self.contentView addSubview:_rightPictureView];
    [_rightPictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rightTitleLabel.mas_right);
        make.centerY.width.height.equalTo(self.leftPictureView);
    }];
    
    _rightContentLabel = [UILabel labelWithTitle:@"-" color:UIColorHex(666666) fontSize:14];
    [self.contentView addSubview:_rightContentLabel];
    [_rightContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.rightPictureView);
    }];
    
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_leftBtn setTitle:@"" forState:UIControlStateNormal];
    [_leftBtn addTarget:self action:@selector(clickImageViewBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_leftBtn];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftPictureView);
        make.top.height.equalTo(self.contentView);
        make.width.mas_equalTo(100 * kScale);
    }];
    
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightBtn addTarget:self action:@selector(clickVideoBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rightPictureView);
        make.top.height.equalTo(self.contentView);
        make.width.equalTo(self.leftBtn);
    }];
    
}


@end
